<template>
  <div>
    <el-form :inline="true" class="demo-form-inline" style="text-align: left">
      <el-form-item label="所在区域">
        <el-input placeholder="所在区域"></el-input>
      </el-form-item>
      <el-form-item label="连接状态">
        <el-select placeholder="连接状态">
          <el-option label="请选择" value=""></el-option>
          <el-option label="在线" value="true"></el-option>
          <el-option label="不在线" value="false"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          style="background-color: green; color: white"
          icon="el-icon-search"
          @click="list"
          >查询</el-button
        >
        <el-button style="color: gray" icon="el-icon-refresh">重置</el-button>
        <el-button style="color: green" icon="el-icon-plus" @click="add"
          >添加</el-button
        >
        <el-button style="color: red" icon="el-icon-delete" @click="del"
          >删除</el-button
        >
        <el-button style="color: orange" icon="el-icon-setting" @click="fantian"
          >修改</el-button
        >
      </el-form-item>
    </el-form>

    <el-dialog title="修改照明" :visible.sync="dialogFormVisible">
      <el-form
        ref="form"
        :model="form1"
        label-width="80px"
        style="width: 500px; margin: 2px auto"
      >
        <el-form-item label="设备编号">
          <el-input v-model="form1.deviceNumber"></el-input>
        </el-form-item>
        <el-form-item label="灯杆编号">
          <el-input v-model="form1.poleNum"></el-input>
        </el-form-item>
        <el-form-item label="所在区域">
          <el-input v-model="form1.area"></el-input>
        </el-form-item>
        <el-form-item label="连接状态" style="width: 50%">
          <el-radio-group v-model="form1.connectionStatus">
            <el-radio :label="true">在线</el-radio>
            <el-radio :label="false">不在线</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="照明状态" style="width: 47%">
          <el-radio-group v-model="form1.illumination">
            <el-radio :label="true">开启</el-radio>
            <el-radio :label="false">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="开启时间">
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="form1.opendate"
              style="width: 419px"
            ></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="关闭时间">
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="form1.closedate"
              style="width: 419px"
            ></el-date-picker>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="baocun">确 定</el-button>
      </div>
    </el-dialog>

    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="deviceNumber" label="设备编号" align="center">
        </el-table-column>
        <el-table-column prop="poleNum" label="灯杆编号" align="center">
        </el-table-column>
        <el-table-column prop="area" label="所在区域" align="center">
        </el-table-column>
        <el-table-column
          prop="connectionStatus"
          label="连接状态"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.connectionStatus ? "在线" : "不在线" }}
          </template>
        </el-table-column>
        <el-table-column prop="illumination" label="照明设备" align="center">
          <template slot-scope="scope">
            {{ scope.row.illumination ? "开启" : "关闭" }}
          </template>
        </el-table-column>
        <el-table-column prop="opendate" label="开启时间" align="center">
        </el-table-column>
        <el-table-column prop="closedate" label="关闭时间" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              style="color: green"
              @click="examine(scope.row)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="countnum"
    >
    </el-pagination>

    <el-dialog
      width="800px"
      height="600px"
      title="照明详情"
      :visible.sync="dialogFormVisible1"
    >
      <span style="float: left">
        <el-button type="primary" circle>1</el-button>基本信息</span
      >
      <br />
      <br />
      <br />
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="180px"
        style="width: 600px; margin: 2px auto"
      >
        <el-form-item label="设备编号" prop="equipmentCoding">
          {{ form.deviceNumber }}
        </el-form-item>
        <el-form-item label="灯杆编号" prop="originalNum">
          {{ form.poleNum }}
        </el-form-item>
        <el-form-item label="所在区域" prop="equipmentName">
          {{ form.area }}
        </el-form-item>
        <el-form-item label="连接状态" prop="equipmentLocaId">
          {{ form.connectionStatus ? "在线" : "不在线" }}
        </el-form-item>
        <el-form-item label="照明设备" prop="deviceType">
          {{ form.illumination ? "开启" : "关闭" }}
        </el-form-item>
        <el-form-item label="开启时间" prop="detailedLocation">
          {{ form.opendate }}
        </el-form-item>
        <el-form-item label="关闭时间" prop="equipmentModel">
          {{ form.closedate }}
        </el-form-item>
      </el-form>

      <span style="float: left">
        <el-button type="primary" circle>2</el-button>运行状态</span
      >
      <br />
      <br />
      <br />
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="180px"
        style="width: 600px; margin: 2px auto"
      >
        <el-form-item label="连接状态" prop="equipmentLocaId">
          {{ form.connectionStatus ? "在线" : "不在线" }}
        </el-form-item>
        <el-form-item label="照明设备" prop="deviceType">
          {{ form.illumination ? "开启" : "关闭" }}
        </el-form-item>
      </el-form>
      <span style="float: left">
        <el-button type="primary" circle>2</el-button>运行记录</span
      >
      <template>
        <el-table :data="tableData" border style="width: 100%">
          <el-table-column prop="id" label="序号" align="center">
          </el-table-column>
          <el-table-column prop="opendate" label="开启时间" align="center">
          </el-table-column>
          <el-table-column prop="closedate" label="关闭时间" align="center">
          </el-table-column>
          <el-table-column prop="duration" label="运行时长" align="center">
            {{ 2023 - 5 - 1 }}
          </el-table-column>
          <el-table-column prop="voltage" label="最大电压" align="center">
            {{ 220 }}V
          </el-table-column>
          <el-table-column prop="electricity" label="最大电流" align="center">
            {{ 220 }}A
          </el-table-column>
        </el-table>
      </template></el-dialog
    >
  </div>
</template>
<script>
import {
  GetShowLightingInfo,
  deleteLightingInfo,
  updLightingInfo,
  GetTotaocount,
} from "@/api/iotInfo/LightingInfo";
export default {
  data() {
    return {
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 0) {
          return "warning-row";
        } else if (rowIndex === 2) {
          return "success-row";
        }
        return "";
      },
      tableData: [],
      dialogFormVisible: false,
      dialogFormVisible1: false,
      multipleSelection: [],
      ids: {},
      form1: {
        id: "",
        deviceNumber: "",
        poleNum: "",
        area: "",
        connectionStatus: true,
        illumination: true,
        opendate: "",
        closedate: "",
      },
      form: {
        deviceNumber: "",
        poleNum: "",
        area: "",
        connectionStatus: "",
        illumination: "",
        opendate: "",
        closedate: "",
      },
      formInline: {
        pageIndex: 1,
        pageSize: 2,
        connectionStatus: "",
      },
      countnum: 0,
      count: 0,
    };
  },
  created() {
    this.list();
    this.totalcount();
  },
  methods: {
    //显示
    list() {
      GetShowLightingInfo(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.list();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
    //全选/反选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //删除
    del() {
      if (this.multipleSelection.length <= 0) {
        this.$message.error("请选择一条数据");
        return;
      }

      this.multipleSelection.forEach((res) => {
        this.ids.id = res.id;
      });
      deleteLightingInfo(this.ids).then((res) => {
        if (res.data) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.list();
        } else {
          this.$message.error("删除失败");
          return;
        }
      });
    },
    //修改
    fantian() {
      if (this.multipleSelection.length != 1) {
        this.$message.error("请选择一条数据");
        return;
      }
      this.dialogFormVisible = true;
      this.multipleSelection.forEach((res) => {
        this.form1 = res;
      });
    },
    baocun() {
      updLightingInfo(this.form1).then((res) => {
        if (res.data) {
          this.$message({
            message: "修改成功",
            type: "success",
          });
          this.list();
          this.dialogFormVisible = false;
        } else {
          this.$message.error("修改失败");
        }
      });
    },
    //详情
    examine(row) {
      this.dialogFormVisible1 = true;
      this.form = row;
    },
    //跳转
    add() {
      this.$router.push("/iotInfo/AddLightingInfo");
    },
  },
};
</script>
<style>
</style>